# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=picolisp
pkgver=24.9
pkgrel=0
pkgdesc="Fast, lightweight Lisp interpreter and application server framework"
url="https://picolisp.com/"
# x86, armv7, armhf: 64-bits only
# riscv64: 6 bytes required for alignment to 8-byte boundary, but only 4 present
# s390x: check fails with "ht:Pack -- Undefined"
arch="all !x86 !armv7 !armhf !riscv64 !s390x"
license="MIT"
depends_doc="w3m"
_llvmver=18
makedepends="
	clang$_llvmver
	libffi-dev
	llvm$_llvmver-dev
	openssl-dev
	readline-dev
	"
subpackages="$pkgname-doc $pkgname-bash-completion"
source="$pkgname-$pkgver.tar.gz::https://software-lab.de/picoLisp-$pkgver.tgz
	fix-shebang-lines.patch
	"
builddir="$srcdir/pil21"

build() {
	PATH="/usr/lib/llvm$_llvmver/bin:$PATH" \
		make -C src
}

check() {
	./pil test/lib.l -bye +
}

package() {
	mkdir -vp "$pkgdir"/usr/bin "$pkgdir"/usr/share
	ln -sv	../lib/$pkgname/bin/picolisp \
		../lib/$pkgname/bin/pil \
		"$pkgdir"/usr/bin/
	ln -sv	../lib/$pkgname \
		"$pkgdir"/usr/share/$pkgname

	# add bash completion
	mkdir -vp "$pkgdir"/usr/share/bash-completion/completions
	mv -v	lib/bash_completion \
		"$pkgdir"/usr/share/bash-completion/completions/pil

	# move documentation
	mkdir -vp "$pkgdir"/usr/share/doc
	chmod -f 644 doc/*.html loc/*
	mv -v doc "$pkgdir"/usr/share/doc/$pkgname
	mv -v COPYING INSTALL README "$pkgdir"/usr/share/doc/$pkgname/
	rm -vf man/man1/pil.1
	ln -sv picolisp.1 man/man1/pil.1
	mv -v man "$pkgdir"/usr/share/

	mkdir -vp "$pkgdir"/usr/lib
	rm -vf pil vip
	mv -v "$builddir" "$pkgdir"/usr/lib/$pkgname
}

doc() {
	default_doc

	mkdir -vp "$subpkgdir"/usr/lib/$pkgname
	ln -sv ../../share/doc/$pkgname "$subpkgdir"/usr/lib/$pkgname/doc
}

sha512sums="
8cd7b43d00b410ad442fd1ee4a0741a75f96700d00563fc168effcc29da8746b9435d6235e33ba8d25d37bd39fd2b09adcc0bf83b4a38d36612b2ce1e36d3904  picolisp-24.9.tar.gz
dd05ba8b0a6bb6dd5d2a0c676240e01a37adfb1413520b934cf6adc50eccbeff01189dc50514d46802385b8c2842afd61b8364947e71d15bfc4f7f030cfb448e  fix-shebang-lines.patch
"
